<?php
include("include/config.inc.php");
$incommingArr = array();
echo $selectincomingProcess = "SELECT planning.incomingId,processId1,processId2,processId3,pro1.processName AS proName1,pro2.processName AS proName2,
                                 pro3.processName AS proName3,temp1,soaking1,furnace1,temp2,soaking2,furnace2,
                                 temp3,soaking3,furnace3,okNotOk1,okNotOk2,okNotOk3
                            FROM planning
                            JOIN process AS pro1 ON planning.processId1 = pro1.processId
                            LEFT JOIN process AS pro2 ON planning.processId2 = pro2.processId
                            LEFT JOIN process AS pro3 ON planning.processId3 = pro3.processId
                           WHERE planningId = ".$_GET['planningId'];
$selectincomingProcessRes = mysql_query($selectincomingProcess);
if($processRow = mysql_fetch_array($selectincomingProcessRes))
{
  $incommingArr['logSheetPlanningId'] = $_GET['planningId'];
  $incommingArr['logSheetIncomingId'] = $_GET['incomingId'];
  $incommingArr['temp1']        = $processRow['temp1'];
  $incommingArr['soaking1']     = $processRow['soaking1'];
  $incommingArr['furnace1']     = $processRow['furnace1'];
  
  $incommingArr['temp2']        = $processRow['temp2'];
  $incommingArr['soaking2']     = $processRow['soaking2'];
  $incommingArr['furnace2']     = $processRow['furnace2'];
  
  $incommingArr['temp3']        = $processRow['temp3'];
  $incommingArr['soaking3']     = $processRow['soaking3'];
  $incommingArr['furnace3']     = $processRow['furnace3'];
  
  $incommingArr['processName1'] = $processRow['proName1'];  
  $incommingArr['processName2'] = $processRow['proName2'];
  $incommingArr['processName3'] = $processRow['proName3'];
  $incommingArr['noOfProcess']  = 0;
  $incommingArr['processId1']   = 0;
  	echo "<br>HI1 :".$processRow['proName1'];
  	echo "<br>HI2 :".$processRow['proName2'];
  	echo "<br>HI3 :".$processRow['proName3'];
  
  
  $selLog = "SELECT COUNT(logSheetId) AS noOfLogSheet
               FROM logsheet 
              WHERE planningId = ".$_GET['planningId']." 
                AND incomingId = ".$_GET['incomingId'];
  $selLogRes = mysql_query($selLog);
  if($logRow = mysql_fetch_array($selLogRes))
  {
  	if($processRow['okNotOk3'] != 1)
  	{
  	  $incommingArr['noOfProcess']   = 1;
  	}
  	if($processRow['okNotOk2'] != 1)
  	{
  	  $incommingArr['noOfProcess']   = $incommingArr['noOfProcess'] + 1;
  	}
  	if($processRow['okNotOk1'] != 1)
  	{
  	  $incommingArr['noOfProcess']   = $incommingArr['noOfProcess'] + 1;
  	}
  }
           
  $selParentId = "SELECT processId1, processId2, processId3, okNotOk1, okNotOk2, okNotOk3, parentPlanningId 
	                  FROM planning
	                 WHERE planningId =".$_GET['planningId'];
  $selParentIdRes = mysql_query($selParentId);
  if($pIdRow = mysql_fetch_array($selParentIdRes))
  {
  	$j = 1;
  	$parentId = $pIdRow['parentPlanningId'];
  	
  	if($pIdRow['okNotOk1'] != 1)
  	{
  		$incommingArr['processId'][$j] = $pIdRow['processId1'];
  		$incommingArr['nameOfProcess'][$j] = $processRow['proName1'];
  		
  		$j++;
  	}
    if($pIdRow['okNotOk2'] != 1)
  	{
  		$incommingArr['processId'][$j] = $pIdRow['processId2'];
  		$incommingArr['nameOfProcess'][$j] = $processRow['proName2'];
  		$j++;
  	}
  	if($pIdRow['okNotOk3'] != 1)
  	{
  		$incommingArr['processId'][$j] = $pIdRow['processId3'];
  		$incommingArr['nameOfProcess'][$j] = $processRow['proName3'];
  	}
;
  	$selOkRecord = "SELECT logsheet.processId,logsheetNo,logsheetDate,startTime,startTemperature,soakingStartTime,endTime,endTemperature,
                           quenchingMedia,quenchingTime,tempBforQue,tempAfterQue,processName,logsheet.status
                      FROM logsheet
                      JOIN process ON process.processId = logsheet.processId
                     WHERE planningId = ".$parentId." 
                       AND status = 'ok' ";
  }
  
  $processArr = getData($_GET['planningId'],$_GET['incomingId']);
}
$smarty->assign("incommingArr",$incommingArr);
$smarty->assign("processArr",$processArr);
$smarty->display('getHide.tpl');

function getData($incomingId)
{
  $processArr = array();
  $i=0;
	$selectincomingProcess = "SELECT logsheet.processId,logsheetNo,logsheetDate,startTime,startTemperature,soakingStartTime,endTime,endTemperature,
                                   quenchingMedia,quenchingTime,tempBforQue,tempAfterQue,processName,logsheet.status
                              FROM logsheet
                              JOIN process ON process.processId = logsheet.processId
                             WHERE planningId = ".$_GET['planningId']." 
                               AND incomingId = ".$_GET['incomingId'];
  $selectincomingProcessRes = mysql_query($selectincomingProcess);
  while($processRow = mysql_fetch_array($selectincomingProcessRes))
  {
    $processArr[$i]['processNo']          = $processRow['processId'];
    $processArr[$i]['processName']        = $processRow['processName'];
    $processArr[$i]['logsheetNo']         = $processRow['logsheetNo'];
    $processArr[$i]['logsheetDate']       = $processRow['logsheetDate'];
    $processArr[$i]['startTime']          = $processRow['startTime'];
    $processArr[$i]['startTemperature']   = $processRow['startTemperature'];
    $processArr[$i]['soakingStartTime']   = $processRow['soakingStartTime'];
    $processArr[$i]['endTime']            = $processRow['endTime'];
    $processArr[$i]['endTemperature']     = $processRow['endTemperature'];
    $processArr[$i]['quenchingMedia']     = $processRow['quenchingMedia'];
    $processArr[$i]['quenchingTime']      = $processRow['quenchingTime'];
    $processArr[$i]['tempBforQue']        = $processRow['tempBforQue'];
    $processArr[$i]['tempAfterQue']       = $processRow['tempAfterQue'];
    $processArr[$i]['status']             = $processRow['status'];
    $processArr[$i]['incomingId']         = $_REQUEST['incomingId'];
    $i++;
  }  
  return $processArr;
}
?>